package com.yanchangapp.ui.presenter;

import com.zxl.baselib.ui.base.BaseActivity;
import com.zxl.baselib.ui.base.BaseObserver;
import com.zxl.baselib.ui.base.BasePresenter;
import com.zxl.baselib.ui.base.ExceptionHandle;
import com.yanchangapp.base.HeadApiRetrofit;
import com.yanchangapp.commom.AppConstant;
import com.yanchangapp.model.response.CntListResponse;
import com.yanchangapp.ui.view.ContactFgView;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by apple on 2019/7/22.
 * description: 联系人fragment页面
 */
public class ContactFgPresenter extends BasePresenter<ContactFgView> {

    public ContactFgPresenter(BaseActivity context) {
        super(context);
    }

    public void queryMailContactLists(){
        HeadApiRetrofit.getInstance()
                .queryMailContacts()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<CntListResponse>() {
                    @Override
                    public void onNext(CntListResponse cntListResponse) {
                        if (cntListResponse.getCode() == AppConstant.REQUEST_SUCCESS){
                            if (getView() != null){
                                getView().queryContactsSuccess(cntListResponse);
                            }
                        }else {
                            if (getView() != null){
                                getView().queryContactFailure(cntListResponse.getMsg());
                            }
                        }
                    }

                    @Override
                    public void onError(ExceptionHandle.ResponseException exception) {
                        if (getView() != null){
                            getView().queryContactFailure("获取联系人失败!");
                        }
                    }
                });
    }
}
